# s0 = "hello world"
#
# for c in s0:
#     print(c)
#
# i = 0
# while i < len(s0):
#     print(s0[i])
#     i += 1


# from collections.abc import Iterable, Iterator
#
# print(isinstance("hello", Iterable), isinstance([], Iterable))
#
# print(isinstance("hello", Iterator), isinstance([], Iterator))
#
# t0 = (i for i in range(10) if i % 2)
# print(type(t0), isinstance(t0, Iterator), isinstance(t0, Iterable))

# for e in t0:
#     print(e)

# e = next(t0)
# print(e)
# e = next(t0)
# print(e)
# e = next(t0)
# print(e)
# e = next(t0)
# print(e)
# e = next(t0)
# print(e)
# e = next(t0)
# print(e)

# while True:
#     try:
#         e = next(t0)
#         print(e)
#     except StopIteration:
#         print(f"异常, 取出来所有元素， 停止")
#         break


# print(max(1, 2, 3), max([1, 2, 3]), max((i for i in range(10))))




from collections.abc import Iterable, Iterator
class MyStr:
    def __init__(self, s):
        self.data = s
        self.index = 0


    def __iter__(self):
        return self

    def __next__(self):
        if self.index >= len(self.data):
            raise StopIteration
        else:
            e = self.data[self.index]
            self.index += 1
            return e

ms = MyStr("睡醒了么")
print(isinstance(ms, Iterable), isinstance(ms, Iterator))

# for i in ms:
#     print(i)

while True:
    try:
        e = next(ms)
        print(e)
    except StopIteration:
        break








